#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef int I;
typedef long long LL;
const I N = 30;
I tc,n,a[N],r[10];
void solve(){
    scanf("%d",&n);
    for(I i = 1;i <= n;i++){
        scanf("%d",&a[i]);
    }
    LL ans = 0;
    for(I i = 0;i < (1 << n);i++){
        LL res = 0;
        r[0] = r[1] = 0;
        for(I j = 1;j <= n;j++){
            I col = ((i >> (j - 1)) & 1);
            if(r[col] == a[j]){
                res += a[j];
            }
            r[col] = a[j];
        }
        ans = max(ans,res);
    }
    printf("%lld\n",ans);
}
void Qingkong(){

}
I main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&tc);
    for(;tc--;){
        solve();
        Qingkong();//duo ce bu qing kong bao ling liang hang lei
    }
    return 0;
}
